<!--
描述：直播课模块-直播课列表
开发人：zhaohang
开发日期：2019年12月25日
-->
<template lang="pug">
  keep-alive
    kalix-table(bizKey="liveAll" title='直播课列表' ref="kalixTable"
    v-bind:tableFields="tableFields"
    v-bind:targetURL="liveAllURL"
    v-bind:bizDialog="liveAllDialog"
    v-bind:btnList="liveAllBtnList"
    v-bind:toolbarBtnList="toolbarBtnList"
    v-bind:customRender="liveAll"
    v-bind:jsonStr="jsonStr"
    bizSearch="liveAllSearch")
      template(slot="tableColumnSlot")
        el-table-column(prop="className" label="课程名称" align="center")
        el-table-column(prop="teacher" label="教师名称" align="center")
        el-table-column(prop="openTime" label="开播时间" align="center" width="100px")
          template(slot-scope="scope")
            span {{dataFormat(scope.row.openTime)}}
        el-table-column(prop="closeTime" label="停播时间" align="center" width="100px")
          template(slot-scope="scope")
            span {{dataFormat(scope.row.closeTime)}}
        el-table-column(prop="classCover" label="课程封面" align="center")
          template(slot-scope="scope")
            img(:src="scope.row.classCover" width="100px" readonly="readonly")
        el-table-column(prop="classIntroduce" label="课程简介" align="center")
          template(slot-scope="scope")
            span {{scope.row.classIntroduce | ellipsis}}
        el-table-column(prop="teacherIntroduce" label="教师简介" align="center")
          template(slot-scope="scope")
            span {{scope.row.teacherIntroduce | ellipsis}}
        el-table-column(prop="courseware" label="课件" align="center")
          template(slot-scope="scope")
            span {{scope.row.courseware | changeStyle}}
        el-table-column(prop="appraise" label="是否评价" align="center")
        el-table-column(prop="recommend" label="是否推荐" align="center")
        el-table-column(prop="personNum" label="开课人数" align="center")
        el-table-column(prop="nowNum" label="已报名人数" align="center")
        el-table-column(prop="isExamine" label="审核状态" align="center")
        el-table-column(prop="overTime" label="报名截止日期" align="center" width="100px")
          <!--template(slot-scope="scope")-->
            <!--span {{dataFormat(scope.row.overTime)}}-->
        el-table-column(prop="isOpen" label="是否开课" align="center")
</template>

<script type="text/ecmascript-6">
  import {liveURL} from '../../config.toml'
  import {liveAllConfigBtnList} from './config'
  import KalixTable from '../../../../../components/corelib/components/common/baseTable'

  export default {
    filters: {
      ellipsis (value) {
        if (!value) return ''
        if (value.length > 8) {
          return value.slice(0, 8) + '...'
        }
        return value
      },
      changeStyle (value) {
        let arr = []
        if (!value) return ''
        if (value.length > 0) {
          if (value.indexOf(',') !== -1) {
            arr = value.split(',')
            arr.forEach((item, i) => {
              arr[i] = item.substring(item.lastIndexOf('/') + 1, item.length)
            })
            value = arr.join(',')
          } else {
            value = value.substring(value.lastIndexOf('/') + 1, value.length)
          }
        }
        return value
      }
    },
    name: 'kalix-mplive-liveall',
    components: {KalixTable},
    data() {
      return {
        // jsonStr: '{"isOpen": "1", "isExamine": "1"}',
        jsonStr: '{"isLiveOpen": "t"}',
        liveAllURL: liveURL,
        tableFields: [
          {prop: 'className', label: '课程名称'},
          {prop: 'teacher', label: '教师名称'},
          {prop: 'openTime', label: '开播时间'},
          {prop: 'closeTime', label: '停播时间'},
          {prop: 'classIntroduce', label: '课程简介'},
          {prop: 'teacherIntroduce', label: '教师简介'},
          {prop: 'classCover', label: '课程封面'},
          {prop: 'appraise', label: '是否评价'},
          {prop: 'recommend', label: '是否推荐'},
          {prop: 'personNum', label: '开课人数'},
          {prop: 'isExamine', label: '审核状态'},
          {prop: 'isOpen', label: '审核状态'},
          {prop: 'overTime', label: '开课日期'},
          {prop: 'nowNum', label: '已报名人数'},
          {prop: 'courseware', label: '课件'}
        ],
        liveAllDialog: [
          {id: 'edit', dialog: 'liveClassRecommend'},
          {id: 'open', dialog: 'liveOpen'},
          {id: 'over', dialog: 'liveOver'}
        ],
        liveAllBtnList: liveAllConfigBtnList,
        toolbarBtnList: [
          {id: 'add', isShow: false, title: '添加', isPermission: true}
        ]
      }
    },
    mounted() {
      this.getUser()
      setTimeout(() => {
      }, 500)
    },
    methods: {
      getUser() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          this.newDataUser = res.data.data
        })
      },
      dataFormat(val) {
        let d = new Date(val)
        return this.$M_FormatDate(d, 'yyyy-MM-dd hh:mm:ss')
      },
      liveAll(_data) {
        if (_data) {
          _data.forEach((e) => {
            e.appraise = e.appraise ? '是' : '否'
            e.recommend = e.recommend ? '是' : '否'
            if (e.isExamine === 0) {
              e.isExamine = '待审核'
            }
            if (e.isExamine === 1) {
              e.isExamine = '通过'
            }
            if (e.isExamine === 2) {
              e.isExamine = '未通过'
            }
            if (e.isOpen === 0) {
              e.isOpen = '待审核'
            }
            if (e.isOpen === 1) {
              e.isOpen = '是'
            }
            if (e.isOpen === 2) {
              e.isOpen = '否'
            }
            if (e.children) {
              this.liveAll(e.children)
            }
          })
        }
        let data = this.$refs.kalixTable.tableData
        for (let i = 0; i < data.length; i++) {
          for (let j = 0; j < this.newDataUser.length; j++) {
            if (data[i].teacherId === this.newDataUser[j].id) {
              this.$refs.kalixTable.tableData[i].teacher = this.newDataUser[j].name
            }
          }
        }
      }
    }
  }
</script>

<style scoped lang="stylus">

</style>
